<?php
/*
 * 功能函数类
 * @package    system
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 47ee5bd6027ebb43b5444acd5b964baab8a3b456 $
 */
class Utils {

	/**
	 * 检测是否url
	 * @param $email
	 * @return bool
	 */
	public static function isEmail($email) {
		return strlen($email) > 6 && preg_match("/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/", $email);
	}

	/**
	 * 检测是否搜索机器人.
	 * @return bool
	 */
	public static function isRobot() {
		if (strpos($_SERVER['HTTP_USER_AGENT'], '://') === false && preg_match("/(MSIE|Netscape|Opera|Konqueror|Mozilla)/i", $_SERVER['HTTP_USER_AGENT'])) {
			return false;
		} else if (preg_match("/(Spider|Bot|Crawl|Slurp|lycos|robozilla)/i", $_SERVER['HTTP_USER_AGENT'])) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 检测IP的匹配
	 * @param $ip
	 * @return int
	 */
	public static function isIp($ip) {
		return preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/", $ip);
	}

	/**
	 * 是否是md5
	 * @param $password
	 * @return int      检测是否32位数字字母的组合
	 */
	public static function isMd5($password) {
		return preg_match("/^[a-z0-9]{32}$/", $password);
	}

	/**
	 * 文件是否是图像
	 * @param $filename
	 * @return bool
	 */
	public static function isImage($filename) {
		return preg_match("/^(jpg|jpeg|gif|png|bmp)$/i", File::ext($filename));
	}
}